package ltd.hxya.novel.user.controller;


import ltd.hxya.novel.common.bean.Result;
import ltd.hxya.novel.common.vo.BookContentParam;
import ltd.hxya.novel.common.vo.UserReadHistoryVo;
import ltd.hxya.novel.user.entity.UserReadHistory;
import ltd.hxya.novel.user.service.IUserReadHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户阅读记录表 前端控制器
 * </p>
 *
 * @author hxya
 * @since 2022-09-13
 */
@RestController
@RequestMapping("/user/readHistory")
public class UserReadHistoryController {


    @Autowired
    private IUserReadHistoryService readHistoryService;
    //修改用户上次阅读的章节
    @PostMapping("/updateReadHistory")
    public Result updateReadHistory(@RequestBody BookContentParam param){
        readHistoryService.updateReadHistory(param.getBookId(), param.getIndexId());
        return Result.success();
    }

    //查询用户上次阅读的章节，并返回章节的值
    @GetMapping("/lastReadIndex/{bookId}")
    public Result<UserReadHistory> lastReadIndex(@PathVariable String bookId){
       UserReadHistory userReadHistory = readHistoryService.lastReadIndex(bookId);


        return Result.success(userReadHistory);
    }

}
